<?php
namespace Realisation\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * Description of ConvertCommand
 *
 * @author pahhan
 */
class MessageConvert extends Command
{
    protected function configure()
    {
        $this
            ->setName('message:convert')
            ->setDescription('Show message for given id')
            ->addArgument('start', InputArgument::REQUIRED)
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $app = \Realisation\App::getInstance();

        for ($index = $input->getArgument('start'); $index < 63435; $index++) {
            $mesage_array = $app['db']->fetchAssoc('SELECT * FROM message WHERE id = ?', array($index));

            if( empty($mesage_array) ) {
                $output->write(' n-'.$index);
            }
            else {
                $count = $app['db']->executeUpdate('UPDATE message SET updated_at = updated_at, content = ? WHERE id = ?', array(mb_convert_encoding($mesage_array['content'], 'UTF-8', 'HTML-ENTITIES'), $index));
                $output->write(' y-'.$index);
            }

        }

    }
}

